﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class ClsSoDuDauKyTaiKhoan
    {
        private string mDienGiai = "";
        private string mKhoa = "";
        private string mKhoaBoPhan = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaDonVi = "";
        private string mKhoaHopDong = "";
        private string mKhoaNguoiDung = "";
        private string mKhoaSanPham = "";
        private string mKhoaTaiKhoan = "";
        private string mLoai = "";
        private string mLoaiTien = "";
        private string mNamThang = "";
        private double mSoDuCo = 0.0;
        private double mSoDuCoNT = 0.0;
        private double mSoDuNo = 0.0;
        private double mSoDuNoNT = 0.0;
        private double mTyGia = 0.0;

        public bool DelData(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, pKhoa);
                commandParameters[1] = DBHelper.createParameter("@CheckAQ", DbType.Double, ParameterDirection.Input, 1);
                commandParameters[2] = DBHelper.createParameter("@pAmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[3] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SoDuDauKyTaiKhoanDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[3].Value, 0, false))
                {
                    if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[2].Value, 0, false))
                    {
                        LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m qũy!", ""));
                    }
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetList(string pNamThang, string pLoai)
        {
            IDataParameter parameter = null;
            DataTable table;
            try
            {
                string commandText = " SELECT SDDK.Khoa, SDDK.NamThang, SDDK.SoDuNoNT, SDDK.SoDuCoNT ,SDDK.KhoaTaiKhoan, TK.SoTaiKhoan as SoTaiKhoan,  SDDK.KhoaDoiTuong, DT.Ten" + modGeneral.H_LANGUAGE + " as DoiTuong,  SDDK.KhoaBoPhan, BP.Ten" + modGeneral.H_LANGUAGE + " as BoPhan,  SDDK.KhoaSanPham, SP.Ten" + modGeneral.H_LANGUAGE + " as SanPham,  SDDK.KhoaHopDong, HD.SoHopDong as HopDong  FROM GL_SoDuDauKyTaiKhoan SDDK\t LEFT JOIN DM_TAIKHOAN TK ON TK.KHOA = SDDK.KHOATAIKHOAN LEFT JOIN DM_DOITUONG DT ON DT.KHOA = SDDK.KHOADOITUONG LEFT JOIN DM_DonViBoPhan BP ON BP.KHOA = SDDK.KHOABOPHAN LEFT JOIN DM_SanPhamCongViec SP ON SP.KHOA = SDDK.KHOASANPHAM LEFT JOIN DM_HopDong HD ON HD.KHOA = SDDK.KHOAHOPDONG WHERE SDDK.NamThang = '" + pNamThang + "' and SDDK.Loai = '" + pLoai + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM GL_SoDuDauKyTaiKhoan WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mNamThang = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoan = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhan = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPham = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mSoDuNoNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoDuNo = Conversions.ToDouble(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoDuCoNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoDuCo = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNguoiDung = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mLoai = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x13];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@KhoaTaiKhoan", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoan);
                commandParameters[3] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[4] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[5] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[6] = DBHelper.createParameter("@KhoaBoPhan", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhan);
                commandParameters[7] = DBHelper.createParameter("@KhoaSanPham", DbType.Int64, ParameterDirection.Input, this.mKhoaSanPham);
                commandParameters[8] = DBHelper.createParameter("@KhoaHopDong", DbType.Int64, ParameterDirection.Input, this.mKhoaHopDong);
                commandParameters[9] = DBHelper.createParameter("@SoDuNoNT", DbType.Date, ParameterDirection.Input, this.mSoDuNoNT);
                commandParameters[10] = DBHelper.createParameter("@SoDuNo", DbType.Date, ParameterDirection.Input, this.mSoDuNo);
                commandParameters[11] = DBHelper.createParameter("@SoDuCoNT", DbType.Date, ParameterDirection.Input, this.mSoDuCoNT);
                commandParameters[12] = DBHelper.createParameter("@SoDuCo", DbType.Date, ParameterDirection.Input, this.mSoDuCo);
                commandParameters[13] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[14] = DBHelper.createParameter("@KhoaNguoiDung", DbType.Int64, ParameterDirection.Input, this.mKhoaNguoiDung);
                commandParameters[15] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[0x10] = DBHelper.createParameter("@Loai", DbType.Int64, ParameterDirection.Input, this.mLoai);
                commandParameters[0x11] = DBHelper.createParameter("@pAmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[0x12] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SoDuDauKyTaiKhoan", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x12].Value, 0, false))
                {
                    if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[0x11].Value, 0, false))
                    {
                        LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m quỹ!", ""));
                    }
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaBoPhan
        {
            get
            {
                return this.mKhoaBoPhan;
            }
            set
            {
                this.mKhoaBoPhan = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaHopDong
        {
            get
            {
                return this.mKhoaHopDong;
            }
            set
            {
                this.mKhoaHopDong = value;
            }
        }

        public string KhoaNguoiDung
        {
            get
            {
                return this.mKhoaNguoiDung;
            }
            set
            {
                this.mKhoaNguoiDung = value;
            }
        }

        public string KhoaSanPham
        {
            get
            {
                return this.mKhoaSanPham;
            }
            set
            {
                this.mKhoaSanPham = value;
            }
        }

        public string KhoaTaiKhoan
        {
            get
            {
                return this.mKhoaTaiKhoan;
            }
            set
            {
                this.mKhoaTaiKhoan = value;
            }
        }

        public string Loai
        {
            get
            {
                return this.mLoai;
            }
            set
            {
                this.mLoai = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public double SoDuCo
        {
            get
            {
                return this.mSoDuCo;
            }
            set
            {
                this.mSoDuCo = value;
            }
        }

        public double SoDuCoNT
        {
            get
            {
                return this.mSoDuCoNT;
            }
            set
            {
                this.mSoDuCoNT = value;
            }
        }

        public double SoDuNo
        {
            get
            {
                return this.mSoDuNo;
            }
            set
            {
                this.mSoDuNo = value;
            }
        }

        public double SoDuNoNT
        {
            get
            {
                return this.mSoDuNoNT;
            }
            set
            {
                this.mSoDuNoNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

